function dbtest(url,tab)
{
	var img_load = $("#text_loading").val();
	//alert(url);
	document.getElementById(""+tab+"").innerHTML = "<img src='" + img_load + "' alt='' height='180'/>";
	//document.getElementById("show_loading").innerHTML = "Loading...";
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  	xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	  	{			  		
	    	document.getElementById(""+tab+"").innerHTML = xmlhttp.responseText;
	    	document.getElementById("show_loading").innerHTML = "";
	    }
	  }			 
	xmlhttp.open("GET",url,true);
	xmlhttp.send();
	return false;
}

function dbagentsend(url,tab)
{
	var img_load = $("#text_loading_agent").val();
	//alert(img_load);
	document.getElementById(""+tab+"").innerHTML = "<img src='" + img_load + "' alt='' height='180'/>";
	//document.getElementById("show_loading").innerHTML = "Loading...";
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  	xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	  	{			  		
	    	document.getElementById(""+tab+"").innerHTML = xmlhttp.responseText;	    	
	    }
	  }			 
	xmlhttp.open("GET",url,true);
	xmlhttp.send();
	return false;
}

$(document).ready(function(){
	
		// su ly dang ky nhan tin qua email
		$("#go_subscriber").click(function(){
		
		var url = $("#go_subscriber").attr('rel');
		var value = $("#submit_subscriber").val();
		value = value.replace("@","00000");
		//alert(value);
		url = url + "?action=subscriber&value=" + value;
		
		if(value=="Enter your email address")
		{
			alert('Please Enter your email.');
			return false;
		}
		else if(value!="Enter your email address")
		{		
			//alert(url);
			document.getElementById("subscriber_show").innerHTML = "Loading...";
			if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  	xmlhttp=new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			xmlhttp.onreadystatechange=function()
			  {
			  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
			  	{			  		
			    	document.getElementById("subscriber_show").innerHTML = xmlhttp.responseText;
			    }
			  }			 
			xmlhttp.open("GET",url,true);
			xmlhttp.send();
			return false;
		}	
							
	});
		
	// su ly tour/hotel trong cac tab theo kieu ajax
	//*****************************************************************************
	$("#tab_vietnam,#tab_lao,#tab_cambodia,#tab_other").click(function(){
		var url =  $("#myprocess_url").val();		
		var show_html = $(this).attr("rel");
		var title = $(this).attr('title');
		var tab = $(this).attr("rel");	
		var page = $("#myprocess_page").val();
		if(show_html=="country6" || show_html=="country7" || show_html=="country8" || show_html=="country5")
		{
			url = url + "?action=tours&page="+page+"&value=" + title;
		}
		else
			url = url + "?action=hotels&page="+page+"&value=" + title;
		//alert(url);
		dbtest(url,tab);
	});
	
	// xu ly search trang tour
	//**************************************************************************/
	$("#submit_go_search").click(function(){
		var length = $("#select_length_of_stay").val();
		var des_from = $("#select_destination_from").val();
		var des_to = $("#select_destination_to").val();
		var vnst = $("#vnst").is(':checked');
		var interst = $("#interst").is(':checked');
		
		if(length=="" && des_from=="" && des_to=="" && (!vnst && !interst))
		{
			$("#select_destination_to").addClass("error");
			$("#select_destination_from").addClass("error");
			$("#select_length_of_stay").addClass("error");
			$("#select_vnst").addClass("select_error");
			$("#select_interst").addClass("select_error");				
						
			return false;
		}
		else if(!vnst && !interst)
		{
			$("#select_vnst").addClass("select_error");
			$("#select_interst").addClass("select_error");
			
			$("#select_destination_to").removeClass("error");
			$("#select_destination_from").removeClass("error");
			$("#select_length_of_stay").removeClass("error");
			
			return false;
		}
		else
		{			
			return true;
		}
		
	});
	
	$(".phantrang").click(function(){
		var value = $(this).attr('rel');
		alert(value);
		return false;
	});
	
});